﻿using System;
using System.Collections.Generic;

using FLEN_Sim.containerobjects;
using FLEN_Sim.config;

namespace FLEN_Sim.funct
{
    public class EmergencyGenerator
    {
        public EmergencyGenerator()
        {
        }

        public static Emergency createRandom()
        {
            //zufälligen Punkt Lat/Lon innerhalb Kreis in Adresse umwandeln
            Random rnd = new Random();
            double max = Config.EN_BOUNDARY_N - 51.0;
            double min = Config.EN_BOUNDARY_S - 51.0;

            double rand_lat = NextDouble(rnd, min, max) + 51.0;

            max = Config.EN_BOUNDARY_E - 7.0;
            min = Config.EN_BOUNDARY_W - 7.0;

            double rand_lon = NextDouble(rnd, min, max) + 7.0;

            string adress = "";
            GMap.NET.PointLatLng p = new GMap.NET.PointLatLng();

            while (p.IsZero)
            {
                adress = GeoCoder.getRandomAdress(1);
                p = GeoCoder.getLocationNominatim(adress, 1);
            }

            return new Emergency(adress, p.Lat, p.Lng);
        }

        private static double NextDouble(Random rng, double min, double max)
        {
            return min + (rng.NextDouble() * (max - min));
        }
    }
}
